#ifndef IP4_IMPL_H
#define IP4_IMPL_H

#include "base_ip.h"
#include "common_defs.h"

#define MIN_IP4_HDR_SIZE    5
#define DEFAUL_TTL          64

namespace usnet {
class IP4Impl : public BaseIP {
public:
    virtual ~IP4Impl() = default;

    static std::unique_ptr<IP4Impl>
    MakeUnique(const PPT proto, EndpointAddr* laddr, EndpointAddr* raddr);

    std::shared_ptr<FrameBufMgr> PrefillHeader() override;

    void SendPacket() override;

    bool RecvPacket() override;

    inline uint32_t GetHeaderSize() const override
    {
        return (hdr_size_ << 2);
    }

    inline uint16_t CheckSum(const FrameBuf* fb) override
    {
        const uint16_t* buf = (const uint16_t*) fb->inet_hdr_.ip4_hdr_;
        return ~static_cast<uint16_t>(InetCheckSum(buf, (hdr_size_ << 1)));
    }

private:
    IP4Impl( const PPT proto, EndpointAddr* laddr, EndpointAddr* raddr):
        BaseIP(proto, laddr, raddr)
    {
        // nothing to do
    }

    uint16_t pktid_ { 0 };
    uint32_t hdr_size_ { MIN_IP4_HDR_SIZE };    // header size in unit of 32-bits
};
} // end of namespace usnet
#endif